#include <iostream>

using namespace std;

const int N = 100010;

int n,heap[N];


// 向上调整
void up(int child){
    int parent = child / 2;
    while(parent >= 1 && heap[child] > heap[parent])
    {
        swap(heap[child],heap[parent]);
        child = parent;
        parent = child / 2;

    }
}

// 向下调整
void down(int parent){
    int child = parent * 2;
    while(child <= n){
        if(child + 1 <= n && heap[child + 1] > heap[child]) child++;
        if(heap[child] <= heap[parent]) return;
        if(heap[child] > heap[parent])
        {
            swap(heap[child],heap[parent]);
            parent = child;
            child = parent * 2;            
        }
    }
}

void push(int x){
    heap[++n] = x;
    up(n);
}

void pop(){
    heap[1] = heap[n];
    n--;
    down(1);
}

int top(){
    return heap[1];
}

int size(){
    return n;
}



int main(){
    int a[10] = {1, 41, 23, 10, 11, 2, -1, 99, 14, 0};
    for(int i = 0;i < 10;i++) push(a[i]);
    while(size() > 0){
        cout << top() << " ";
        pop();
    }
    
    return 0;
}